<?php
class FP_User extends FP_Model implements Zend_Acl_Role_Interface
{

    protected $_role = null;
    protected $_permissions = null;

    protected $_confirm_password = null;

    protected $_data = array(
        'user_id' => null,
        'role_id' => null,
        'username' => null,
        'password' => null,
        'status' => null,
        'email' => null,
        'first_name' => null,
        'last_name' => null,
        'active_at' => null,
        'created_at' => null,
        'updated_at' => null
    );

    public function getRoleId(){
	return 'user-' . strtolower($this->username);

    }

    public function authenticate($pPassword){
	logdebug("FP_User.authenticate: Comparing " . md5($pPassword) . " to {$this->password}");
	return (FP_Application::EncryptPassword($pPassword) == $this->password);
    }

    public function isAdministrator(){
	$role = $this->getRole();
	return ($role->name == 'Administrator');
    }

    public function isActive(){

	return $this->status == USER_STATUS_ACTIVE;

    }

    public function isDisabled(){

	return $this->status == USER_STATUS_DISABLED;
    }

    public function setRole($pRole){
	if (is_numeric($pRole))
	    $this->role_id = $pRole;
	else
	    $this->role_id = $this->gateway->getRoleId($pRole);

    }

    public function flushPermissions(){
	$this->_permissions = null;
    }

    public function __get($pAtt){
	switch ($pAtt){
	    case 'fullName':
		return "{$this->first_name} {$this->last_name}";
	    default:
		return parent::__get($pAtt);
	}

    }

    public function __set($pAtt, $pVal){

	switch ($pAtt){
	    case 'role':
		$this->setRole($pVal);
		break;
	    case 'confirm_password':
		$this->_confirm_password = $pVal;
		break;
	    default:
		parent::__set($pAtt, $pVal);
	}

    }
}

 ?>